package com.ruangong.GitClient.app.TravelExpense;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
import com.ruangong.GitClient.R;

import java.util.List;

public class AddExpenseActivity extends AppCompatActivity {
    private EditText expenseNameEditText;
    private EditText expenseAmountEditText;
    private int eventId; // Event ID

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_addexpense);

        // Initialize views
        expenseNameEditText = findViewById(R.id.editTextExpenseName);
        expenseAmountEditText = findViewById(R.id.editTextExpenseAmount);
        Button addButton = findViewById(R.id.buttonSaveExpense);

        // Set up button click listener
        addButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Retrieve expense name and amount from EditText fields
                String expenseName = expenseNameEditText.getText().toString().trim();
                String expenseAmountText = expenseAmountEditText.getText().toString().trim();

                // Validate expense amount
                if (expenseName.isEmpty()) {
                    expenseNameEditText.setError("Expense name is required");
                    return;
                }

                if (expenseAmountText.isEmpty()) {
                    expenseAmountEditText.setError("Expense amount is required");
                    return;
                }

                try {
                    double expenseAmount = Double.parseDouble(expenseAmountText);
                    // Create an Intent to return data to TravelEventsDetailsActivity
                    Intent resultIntent = new Intent();
                    resultIntent.putExtra("expenseName", expenseName);
                    resultIntent.putExtra("expenseAmount", expenseAmount);
                    setResult(RESULT_OK, resultIntent);
                    finish(); // Close AddExpenseActivity
                } catch (NumberFormatException e) {
                    expenseAmountEditText.setError("Invalid expense amount");
                }
            }
        });
    }
}







